<?php

/**
 * PluginMidia form.
 *
 * @package    form
 * @subpackage Midia
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
abstract class PluginMidiaForm extends BaseMidiaForm
{
	
  public function configure()
  {
  		parent::configure();
  	
	  	$this->widgetSchema['nm_midia']     = new sfWidgetFormInputFile();
      	$this->widgetSchema['ds_midia']     = new sfWidgetFormInput();
      	$this->validatorSchema['nm_midia']  = new MidiaValidatorFile(array('path' => sfConfig::get('sf_upload_dir'), 'required' => false, 'mime_types' => 'web_images'));
      
      	$this->widgetSchema->setLabels(array(
                                      'nm_midia'         => 'Arquivo',
                                      'ds_midia'           => 'Descrição'
                                    ));
                                
	    $this->validatorSchema->setOption('allow_extra_fields', true);
	      
	    $this->widgetSchema->setNameFormat('midia[%s]');
  }

  /*Sobreescrita do método doSave, para PODER salvar thumbnail =/ */
   protected function doSave ( $con = null )
   {
       //remove o thumb anterior
       $thumb_pre   = sfConfig::get('sf_thumbnail_dir').'/'.$this->getObject()->getNmMidia();
       if(file_exists($thumb_pre)) unlink(sfConfig::get('sf_thumbnail_dir').'/'.$this->getObject()->getNmMidia());

       //salvando a imagem. O Objeto é entao atualizado
       parent::doSave();

       //Salvando o thumbnail
       $midia   = new Midia();
       $midia->createThumb($this);
  }
}